//使用node的path模块
const path = require('path');

//引入vue-loader插件
const VueLoaderPlugin = require('vue-loader/lib/plugin');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const { CleanWebpackPlugin } = require('clean-webpack-plugin');

const webpack = require('webpack');

const isDev = process.env.NODE_ENV === 'development';

module.exports = {
    //打包入口
    entry: './src/main.js',
    // devtool:'eval',
    devServer: {
        static: {
            directory: path.join(__dirname, 'dist'),
        },
        open:true,
        host: 'localhost',      // 默认是localhost
        port: 8088,             // 端口
        hot: true,
    },
    //打包出口
    output: {
        filename: "app.js",
        path: path.resolve(__dirname, 'dist')
    },
    mode: 'development', //生产环境
    //打包规则
    module: {
        rules: [{
            test: /\.vue$/,
            loader: 'vue-loader'
        },
            {
                test: /\.(png|jpg|jpeg|svg)$/,
                loader: 'url-loader',
                options: {
                    name: '[name].[ext]',
                    limit: 1024*300,
                    esModule: false    // 禁用es模块
                },
                type: 'javascript/auto',
            },
            {
                test: /\.css$/,
                use: ['style-loader','css-loader'],
            },
            {
                test: /\.styl(us)?$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'postcss-loader',
                    'stylus-loader'
                ]
            },
            {
                test:/\.js$/,
                exclude: /node_modules/,
                loader: "babel-loader"
            }]
    },
    //插件
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            template: "./index.html"
        }),
        new CleanWebpackPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve: {
        alias: {
            'vue':'vue/dist/vue.js'
        }
    }
};